# -*- mode: python -*-

Import("env")

env = env.Clone()
env.InjectThirdParty(libraries=["grpc"])

env.CppUnitTest(
    target="grpc_transport_layer_test",
    source=[
        "channel_pool_test.cpp",
        "client_cache_test.cpp",
        "grpc_client_test.cpp",
        "grpc_session_test.cpp",
        "grpc_transport_layer_test.cpp",
        "mock_client_test.cpp",
        "mock_server_stream_test.cpp",
        "mock_stub_test.cpp",
        "reactor_test.cpp",
        "server_test.cpp",
        "service_test.cpp",
    ],
    LIBDEPS=[
        "$BUILD_DIR/mongo/base",
        "$BUILD_DIR/mongo/db/service_context_non_d",
        "$BUILD_DIR/mongo/db/service_context_test_fixture",
        "$BUILD_DIR/mongo/db/wire_version",
        "$BUILD_DIR/mongo/rpc/message",
        "$BUILD_DIR/mongo/transport/service_executor",
        "$BUILD_DIR/mongo/util/clock_source_mock",
        "$BUILD_DIR/mongo/util/periodic_runner_factory",
        "$BUILD_DIR/third_party/grpc/grpc++_reflection",
        "$BUILD_DIR/third_party/protobuf/protobuf",
        "grpc_transport_layer",
        "grpc_transport_mock",
    ],
)

protoEnv = env.Clone()
protoEnv.InjectThirdParty(libraries=["proto"])
protoEnv.AppendUnique(
    PROTOC_GEN_TYPES=[["cpp", protoEnv.Dir(".")]],
    PROTOC_PLUGINS={
        "grpc": {
            "plugin": "$PROTOC_GRPC_PLUGIN",
            "options": ["generate_mock_code=true"],
            "gen_out": protoEnv.Dir("."),
            "exts": [".grpc.pb.cc", ".grpc.pb.h"],
        },
    },
    CPPPATH=[protoEnv.Dir(".")],
)
protoEnv.Append(
    CPPPATH=[
        "$BUILD_DIR/third_party/protobuf/dist/src",
        "#/bazel-bin",
    ]
)

protoEnv.CppUnitTest(
    target="grpc_core_test",
    source=[
        "core_test.cpp",
    ],
    LIBDEPS=[
        "$BUILD_DIR/mongo/base",
        "$BUILD_DIR/third_party/grpc/grpc++_reflection",
        "$BUILD_DIR/third_party/protobuf/protobuf",
        "core_test_cc_grpc",
    ],
)
